﻿using Com.Aote.Behaviors;
using Com.Aote.ObjectTools;
using Com.Aote.Utils;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Com.Aote.Pages
{
	public partial class 机表预存补打 : UserControl
	{
        public 机表预存补打()
		{
			// Required to initialize variables
			InitializeComponent();
		}

        private void save_Click(object sender, RoutedEventArgs e)
        {
            GeneralObject LoginUsershouju = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "LoginUsershouju");
            LoginUsershouju.DataLoaded += LoginUsershouju_DataLoaded;
            LoginUsershouju.Load();
        }

        void LoginUsershouju_DataLoaded(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            GeneralObject LoginUsershouju = sender as GeneralObject;
            LoginUsershouju.DataLoaded -= LoginUsershouju_DataLoaded;
            //if (e.Error != null)
            //{
            //    MessageBox.Show("没有分配收据号，不能打印！");
            //    return;
            //}
            //string shoujuhao = LoginUsershouju.GetPropertyValue("shoujuhao") + "";
            //if (string.IsNullOrEmpty(shoujuhao))
            //{
            //    MessageBox.Show("没有分配收据号，不能打印！");
            //    return;
            //}
            print.TipCompleted -= print_TipCompleted;
            print.TipCompleted += print_TipCompleted;
            print.TipNoPrint();
        }

        void print_TipCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            print.TipCompleted -= print_TipCompleted;
            GeneralObject kbfee = userfile.DataContext as GeneralObject;
            string f_invoicenum = kbfee.GetPropertyValue("f_invoicenum") + "";
            GeneralObject shouju = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "shouju");
            shouju.SetPropertyValue("f_shoujustatue", "作废", true);

            GeneralObject fpinfosobj = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "fpinfosobj");
            fpinfosobj.SetPropertyValue("f_shoujustatue", "已用", true);

            GeneralObject sellinggas = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "sellinggas");
            sellinggas.SetPropertyValue("f_invoicenum", f_invoicenum, true);

            MessageBox.Show("当前打印收据号：" + f_invoicenum);

            BatchExcuteAction SaveAction = (BatchExcuteAction)FrameworkElementExtension.FindResource(this.save, "SaveAction");
            SaveAction.Invoke();

            print.UseDefaultPrinter = true;
            //print.Completed += print_Completed;
            print.Print();
        }

        void print_Completed(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            print.Completed -= print_Completed;
        }
	}
}